package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysRoleService;
import com.atguigu.spzx.model.dto.system.SysRoleDto;
import com.atguigu.spzx.model.entity.system.SysRole;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wx
 * @version 1.0
 * @description: TODO
 * @date 2024/11/7 18:12
 */
@RestController
@RequestMapping("/admin/system/sysRole")
@Tag(name = "角色管理接口")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @PutMapping("/updateSysRole")
    public Result updateSysRole(@RequestBody SysRole sysRole) {
        sysRoleService.updateSysRole(sysRole);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 条件分页查询角色列表
     * @param sysRoleDto
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/findByPage/{pageNum}/{pageSize}")
    @Operation(summary = "分页查询角色列表")
    public Result<PageInfo<SysRole>> findByPage(SysRoleDto sysRoleDto,
                                                @PathVariable("pageNum") Integer pageNum,
                                                @PathVariable("pageSize") Integer pageSize) {
        PageInfo<SysRole> pageRoleInfo = sysRoleService.findByPage(sysRoleDto, pageNum, pageSize);
        return Result.build(pageRoleInfo, ResultCodeEnum.SUCCESS);
    }

    /**
     * 保存角色
     * @param sysRole
     * @return
     */
    @PostMapping("/save")
    @Operation(summary = "添加角色")
    public Result save(@RequestBody SysRole sysRole) {
        sysRoleService.saveSysRole(sysRole);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 根据id删除角色
     * @param id
     * @return
     */
    @DeleteMapping("/deleteSysRoleById/{id}")
    @Operation(summary = "删除角色")
    public Result deleteSysRoleById(@PathVariable Long id){
        sysRoleService.deleteSysRoleById(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

}
